package formularios;

import java.sql.SQLException;
import javax.swing.event.ListSelectionListener;
import negocios.Aluno;
import dao.AlunoDAO;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.table.DefaultTableModel;

public final class FormAlunoPrincipal extends javax.swing.JFrame {

    DefaultTableModel tmAluno = new DefaultTableModel(null, new String[]{"Serie", "Turma", "Numero", "Nome", "Curso", "Telefone", "Id"});
    List<Aluno> Aluno;
    ListSelectionModel lsmAluno;

    public FormAlunoPrincipal() throws SQLException {
        initComponents();
        setExtendedState(MAXIMIZED_BOTH);
        jTF_id.setEditable(false);
        listarAluno();

    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jTF_pesquisa = new javax.swing.JTextField();
        jB_pesquisar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTTable_aluno = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTF_nome = new javax.swing.JTextField();
        jTF_numero = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jTF_telefone = new javax.swing.JTextField();
        jTF_id = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jTF_serie = new javax.swing.JComboBox();
        jTF_curso = new javax.swing.JComboBox();
        jTF_turma = new javax.swing.JComboBox();
        jPanel3 = new javax.swing.JPanel();
        jB_novo = new javax.swing.JButton();
        jB_salvar = new javax.swing.JButton();
        jB_excluir = new javax.swing.JButton();
        jB_voltar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("SGB (Sistema Gerenciador da Biblioteca)");

        jPanel1.setBackground(new java.awt.Color(204, 255, 204));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 3, true), "Aluno", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 18), new java.awt.Color(0, 102, 0))); // NOI18N

        jTF_pesquisa.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));
        jTF_pesquisa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTF_pesquisaActionPerformed(evt);
            }
        });
        jTF_pesquisa.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTF_pesquisaKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTF_pesquisaKeyReleased(evt);
            }
        });

        jB_pesquisar.setBackground(new java.awt.Color(255, 255, 255));
        jB_pesquisar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Png/Figura1.PNG"))); // NOI18N
        jB_pesquisar.setText("Pesquisar");
        jB_pesquisar.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEtchedBorder(new java.awt.Color(0, 102, 0), java.awt.Color.white), new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 1, true)));
        jB_pesquisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jB_pesquisarActionPerformed(evt);
            }
        });

        jScrollPane1.setBackground(new java.awt.Color(153, 255, 153));
        jScrollPane1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 1, true));
        jScrollPane1.setForeground(new java.awt.Color(0, 102, 0));
        jScrollPane1.setViewportBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 1, true));
        jScrollPane1.setFont(new java.awt.Font("Tahoma", 0, 12));
        jScrollPane1.setOpaque(false);
        jTTable_aluno.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        lsmAluno = jTTable_aluno.getSelectionModel();
        lsmAluno.addListSelectionListener(new ListSelectionListener(){
            public void valueChanged(ListSelectionEvent e){
                if(! e.getValueIsAdjusting()){
                    JTTabelaLinhaSelecionada(jTTable_aluno);
                }
            }
        });

        jTTable_aluno.setBackground(new java.awt.Color(204, 255, 204));
        jTTable_aluno.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 1, true));
        jTTable_aluno.setFont(new java.awt.Font("Tahoma", 1, 12));
        jTTable_aluno.setForeground(new java.awt.Color(0, 153, 0));
        jTTable_aluno.setModel(tmAluno);
        jTTable_aluno.setGridColor(new java.awt.Color(0, 102, 0));
        jTTable_aluno.setSelectionBackground(new java.awt.Color(153, 255, 153));
        jTTable_aluno.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        lsmAluno = jTTable_aluno.getSelectionModel();
        lsmAluno.addListSelectionListener(new ListSelectionListener(){
            public void valueChanged(ListSelectionEvent e){
                if(! e.getValueIsAdjusting()){
                    JTTabelaLinhaSelecionada(jTTable_aluno);
                }
            }
        });
        jScrollPane1.setViewportView(jTTable_aluno);

        jPanel2.setBackground(new java.awt.Color(204, 255, 204));
        jPanel2.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

        jLabel1.setFont(new java.awt.Font("Segoe UI Symbol", 1, 14));
        jLabel1.setText("Nome:");

        jLabel2.setFont(new java.awt.Font("Segoe UI Symbol", 1, 14));
        jLabel2.setText("Serie:");

        jLabel3.setFont(new java.awt.Font("Segoe UI Symbol", 1, 14));
        jLabel3.setText("Turma:");

        jLabel4.setFont(new java.awt.Font("Segoe UI Symbol", 1, 14));
        jLabel4.setText("Curso:");

        jTF_nome.setFont(new java.awt.Font("Tahoma", 1, 14));
        jTF_nome.setForeground(new java.awt.Color(0, 102, 0));
        jTF_nome.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 1, true));

        jTF_numero.setFont(new java.awt.Font("Tahoma", 1, 14));
        jTF_numero.setForeground(new java.awt.Color(0, 102, 0));
        jTF_numero.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 1, true));
        jTF_numero.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTF_numeroActionPerformed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Segoe UI Symbol", 1, 14));
        jLabel5.setText("Nº:");

        jLabel6.setFont(new java.awt.Font("Segoe UI Symbol", 1, 14));
        jLabel6.setText("Telefone:");

        jTF_telefone.setFont(new java.awt.Font("Tahoma", 1, 14));
        jTF_telefone.setForeground(new java.awt.Color(0, 102, 0));
        jTF_telefone.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 1, true));

        jTF_id.setFont(new java.awt.Font("Tahoma", 1, 14));
        jTF_id.setForeground(new java.awt.Color(0, 102, 0));
        jTF_id.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 1, true));
        jTF_id.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTF_idActionPerformed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Segoe UI Symbol", 1, 14));
        jLabel7.setText("Id:");

        jTF_serie.setForeground(new java.awt.Color(0, 102, 0));
        jTF_serie.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Serie?", "1", "2", "3" }));
        jTF_serie.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

        jTF_curso.setForeground(new java.awt.Color(0, 102, 0));
        jTF_curso.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Curso?", "Administração", "Comércio", "Enfermagem", "Infomática" }));
        jTF_curso.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

        jTF_turma.setForeground(new java.awt.Color(0, 102, 0));
        jTF_turma.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Turma?", "A", "B", "C", "D" }));
        jTF_turma.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(jLabel1)
                    .addComponent(jLabel5)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jTF_id, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jTF_serie, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jTF_turma, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGap(18, 18, 18)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING))
                            .addGap(18, 18, 18)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jTF_curso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jTF_telefone, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(jTF_numero, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTF_nome, javax.swing.GroupLayout.DEFAULT_SIZE, 338, Short.MAX_VALUE))
                .addContainerGap())
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel3, jLabel4});

        jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jTF_id, jTF_numero});

        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jTF_id, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTF_nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addGap(14, 14, 14)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTF_numero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTF_serie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4)
                            .addComponent(jTF_curso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jTF_turma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel3))
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jTF_telefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel6)))))
                .addContainerGap(25, Short.MAX_VALUE))
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jTF_id, jTF_nome, jTF_numero, jTF_serie, jTF_telefone});

        jPanel3.setBackground(new java.awt.Color(204, 255, 204));
        jPanel3.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 2, true));

        jB_novo.setBackground(new java.awt.Color(255, 255, 255));
        jB_novo.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jB_novo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Png/Figura3.png"))); // NOI18N
        jB_novo.setText("Novo");
        jB_novo.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEtchedBorder(new java.awt.Color(0, 102, 0), java.awt.Color.white), new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 1, true)));
        jB_novo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jB_novoActionPerformed(evt);
            }
        });

        jB_salvar.setBackground(new java.awt.Color(255, 255, 255));
        jB_salvar.setFont(new java.awt.Font("Tahoma", 1, 12));
        jB_salvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Png/Figura7.png"))); // NOI18N
        jB_salvar.setText("Salvar");
        jB_salvar.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEtchedBorder(new java.awt.Color(0, 102, 0), java.awt.Color.white), new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 1, true)));
        jB_salvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jB_salvarActionPerformed(evt);
            }
        });

        jB_excluir.setBackground(new java.awt.Color(255, 255, 255));
        jB_excluir.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jB_excluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Png/figura0.png"))); // NOI18N
        jB_excluir.setText("Excluir");
        jB_excluir.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEtchedBorder(new java.awt.Color(0, 102, 0), java.awt.Color.white), new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 1, true)));
        jB_excluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jB_excluirActionPerformed(evt);
            }
        });

        jB_voltar.setBackground(new java.awt.Color(255, 255, 255));
        jB_voltar.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jB_voltar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Png/Figura6.png"))); // NOI18N
        jB_voltar.setText("Voltar");
        jB_voltar.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEtchedBorder(new java.awt.Color(0, 102, 0), java.awt.Color.white), new javax.swing.border.LineBorder(new java.awt.Color(0, 102, 0), 1, true)));
        jB_voltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jB_voltarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addComponent(jB_voltar, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jB_novo, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jB_salvar, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jB_excluir, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE)
                .addGap(35, 35, 35))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jB_excluir)
                    .addComponent(jB_salvar)
                    .addComponent(jB_novo, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jB_voltar, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jB_excluir, jB_novo, jB_salvar, jB_voltar});

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1111, Short.MAX_VALUE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jTF_pesquisa, javax.swing.GroupLayout.DEFAULT_SIZE, 974, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jB_pesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(342, 342, 342)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(340, 340, 340)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTF_pesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jB_pesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 286, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jB_pesquisar, jTF_pesquisa});

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-1155)/2, (screenSize.height-717)/2, 1155, 717);
    }// </editor-fold>//GEN-END:initComponents

    private void jB_novoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_novoActionPerformed
        limpadados();
    }//GEN-LAST:event_jB_novoActionPerformed

    private void jB_salvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_salvarActionPerformed
        if (verificaDados()) {
            String iaa = jTF_id.getText();
            if ("".equals(iaa)) {
                try {
                    cadastrar();
                    listarAluno();
                    limpadados();
                } catch (SQLException ex) {
                    Logger.getLogger(FormAlunoPrincipal.class.getName()).log(Level.SEVERE, null, ex);
                }

            } else {
                try {
                    alteraAlunor();
                    limpadados();
                    listarAluno();
                } catch (SQLException ex) {
                    Logger.getLogger(FormAlunoPrincipal.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        } else {
            JOptionPane.showMessageDialog(null, "Campos não preenchidos");
        }
        try {
            listarAluno();
        } catch (SQLException ex) {
            Logger.getLogger(FormAlunoPrincipal.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jB_salvarActionPerformed

    private void jB_excluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_excluirActionPerformed
        try {
            excluirAluno();
            listarAluno();
        } catch (SQLException ex) {
            Logger.getLogger(FormAlunoPrincipal.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jB_excluirActionPerformed

    private void jB_voltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_voltarActionPerformed
        dispose();
    }//GEN-LAST:event_jB_voltarActionPerformed

    private void jB_pesquisarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_pesquisarActionPerformed

        try {
            listarAluno();
        } catch (SQLException ex) {
            Logger.getLogger(FormAlunoPrincipal.class.getName()).log(Level.SEVERE, null, ex);
        }


    }//GEN-LAST:event_jB_pesquisarActionPerformed

    private void jTF_numeroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTF_numeroActionPerformed
    }//GEN-LAST:event_jTF_numeroActionPerformed

    private void jTF_idActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTF_idActionPerformed
    }//GEN-LAST:event_jTF_idActionPerformed

    private void jTF_pesquisaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTF_pesquisaKeyPressed
    }//GEN-LAST:event_jTF_pesquisaKeyPressed

    private void jTF_pesquisaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTF_pesquisaActionPerformed
    }//GEN-LAST:event_jTF_pesquisaActionPerformed

    private void jTF_pesquisaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTF_pesquisaKeyReleased
        try {
            listarAluno();
        } catch (SQLException ex) {
            Logger.getLogger(FormAlunoPrincipal.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_jTF_pesquisaKeyReleased
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jB_excluir;
    private javax.swing.JButton jB_novo;
    private javax.swing.JButton jB_pesquisar;
    private javax.swing.JButton jB_salvar;
    private javax.swing.JButton jB_voltar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JComboBox jTF_curso;
    private javax.swing.JTextField jTF_id;
    private javax.swing.JTextField jTF_nome;
    private javax.swing.JTextField jTF_numero;
    private javax.swing.JTextField jTF_pesquisa;
    private javax.swing.JComboBox jTF_serie;
    private javax.swing.JTextField jTF_telefone;
    private javax.swing.JComboBox jTF_turma;
    private javax.swing.JTable jTTable_aluno;
    // End of variables declaration//GEN-END:variables

    protected void listarAluno() throws SQLException {
        AlunoDAO dao = new AlunoDAO();
        Aluno = dao.Buscar(jTF_pesquisa.getText() + "%");
        mostraPesquisa(Aluno);

    }

    public void cadastrar() throws SQLException {
        //jcb_pesquisa.setSelectedItem(tf_nome.getText());
        Aluno a = new Aluno();
        
        a.setNumero(jTF_numero.getText());
        a.setNome(jTF_nome.getText());
        a.setSerie((String) jTF_serie.getSelectedItem());
        a.setTurma((String) jTF_turma.getSelectedItem());
        a.setCurso((String) jTF_curso.getSelectedItem());
        a.setTelefone(jTF_telefone.getText());
        AlunoDAO dao = new AlunoDAO();
        dao.adicionar(a);
    }

    private void mostraPesquisa(List<Aluno> Aluno) {
        // Zerando a lista de pesquisa !
        while (tmAluno.getRowCount() > 0) {
            tmAluno.removeRow(0);
        }
        if (Aluno.isEmpty()) {
        } else {
            String[] linha = new String[]{null, null, null, null, null, null, null};
            for (int i = 0; i < Aluno.size(); i++) {
                tmAluno.addRow(linha);
                tmAluno.setValueAt(Aluno.get(i).getSerie(), i, 0);
                tmAluno.setValueAt(Aluno.get(i).getTurma(), i, 1);
                tmAluno.setValueAt(Aluno.get(i).getNumero(), i, 2);
                tmAluno.setValueAt(Aluno.get(i).getNome(), i, 3);
                tmAluno.setValueAt(Aluno.get(i).getCurso(), i, 4);
                tmAluno.setValueAt(Aluno.get(i).getTelefone(), i, 5);
                tmAluno.setValueAt(Aluno.get(i).getId(), i, 6);
            }
        }
    }

    private void JTTabelaLinhaSelecionada(JTable tabela) {
        if (jTTable_aluno.getSelectedRow() > -1) {
            jTF_id.setText(String.valueOf(Aluno.get(tabela.getSelectedRow()).getId()));
            jTF_numero.setText((Aluno.get(tabela.getSelectedRow()).getNumero()));
            jTF_nome.setText((Aluno.get(tabela.getSelectedRow()).getNome()));
            jTF_serie.setSelectedItem((Aluno.get(tabela.getSelectedRow()).getSerie()));
            jTF_turma.setSelectedItem((Aluno.get(tabela.getSelectedRow()).getTurma()));
            jTF_curso.setSelectedItem((Aluno.get(tabela.getSelectedRow()).getCurso()));
            jTF_telefone.setText((Aluno.get(tabela.getSelectedRow()).getTelefone()));
        } else {
            limpadados();
        }
    }

    public boolean verificaDados() {
        if (!jTF_nome.getText().equals("") && !jTF_serie.getSelectedItem().equals("Serie?") && !jTF_turma.getSelectedItem().equals("Turma?") && !jTF_curso.getSelectedItem().equals("Curso?") && !jTF_numero.getText().equals("")) {
            return true;
        } else {
            return false;
        }
    }

    public void alteraAlunor() throws SQLException {
        if (jTTable_aluno.getSelectedRow() >= 0) {
            if (verificaDados()) {
                Aluno c1 = new Aluno();
                AlunoDAO dao = new AlunoDAO();
                c1.setId(Long.valueOf(jTF_id.getText()));
                c1.setNumero(jTF_numero.getText());
                c1.setNome(jTF_nome.getText());
                c1.setSerie((String) jTF_serie.getSelectedItem());
                c1.setTurma((String) jTF_turma.getSelectedItem());
                c1.setCurso((String) jTF_curso.getSelectedItem());
                c1.setTelefone(jTF_telefone.getText());
                dao.altera(c1);
            }
        }
    }

    private void excluirAluno() throws SQLException {

        int resp = JOptionPane.showConfirmDialog(this, "Deseja realmente excluir este contato?",
                "Confirmação", JOptionPane.YES_NO_OPTION);

        if (resp == JOptionPane.YES_NO_OPTION) {
            AlunoDAO dao = new AlunoDAO();
            dao.excluirAluno(Aluno.get(jTTable_aluno.getSelectedRow()));
            mostraPesquisa(Aluno);


        }

    }

    public void limpadados() {
        jTF_id.setText("");
        jTF_numero.setText("");
        jTF_nome.setText("");
        jTF_serie.setSelectedItem("Serie?");
        jTF_turma.setSelectedItem("Turma?");
        jTF_curso.setSelectedItem("Curso?");
        jTF_numero.setText("");
        jTF_telefone.setText("");
    }
}